DXL Syntax for typecasting an array

I have successfully used the syntax below to return an array of strings (for example) from a function:

string functionThatReturnsStringArray(int i)[] {
    string str[];
    int temp = (int get(arrayWithSimpleStringsArrayAsElements, i, 0)); 
    str = (addr_ temp);
    return (str);
}
 
// Usage:
 
string myStr[];
myStr = functionThatReturnsStringArray(20);

 


I like to keep use of "addr_" to a minimum. Does DXL have a syntax to day "Cast the value retrieved as string[]".

Logically, I would like to do the below (but it does not compile):

 

 

string functionThatReturnsStringArray(int i)[] {
    string str[];
    str = (string[] get(arrayWithSimpleStringsArrayAsElements, i, 0)); 
    return (str);
}



Anyone know a syntactically valid, straightforward cast without playing pointer games?



 


SystemAdmin - Fri May 14 14:07:40 EDT 2010

Re: DXL Syntax for typecasting an array
Mathias Mamsch - Fri May 14 15:03:38 EDT 2010

It is actually very simple:
 

Array arrayWithSimpleStringsArrayAsElements = create(3,3)
 
string s[] = {"Hello","DXL"}
 
put (arrayWithSimpleStringsArrayAsElements ,s,0,0 )
 
string functionThatReturnsStringArray(int i)[] {
    string str[];
    str = get(arrayWithSimpleStringsArrayAsElements, i, 0) ; 
    return (str);
}
 
string myStr[];
myStr = functionThatReturnsStringArray(0);
 
print myStr[0] " " myStr[1] "\n"

 


My suggestion is to avoid the

 

string function(parameters)[] { ... }

syntax. I had a bad error once using this syntax which was very hard to track down ... It seems to work very nice, but somehow it messes up the stack once in a while - unfortunately I cannot give an example. Just an advice - If you ever run into weird problems in any program part that make no sense, and you are using a function with that syntax change it back to void func(string &par[]) which does the trick but seems to be more stable.

Regards, Mathias
 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: DXL Syntax for typecasting an array
SystemAdmin - Thu May 27 11:08:52 EDT 2010

Mathias Mamsch - Fri May 14 15:03:38 EDT 2010

It is actually very simple:
 

Array arrayWithSimpleStringsArrayAsElements = create(3,3)
 
string s[] = {"Hello","DXL"}
 
put (arrayWithSimpleStringsArrayAsElements ,s,0,0 )
 
string functionThatReturnsStringArray(int i)[] {
    string str[];
    str = get(arrayWithSimpleStringsArrayAsElements, i, 0) ; 
    return (str);
}
 
string myStr[];
myStr = functionThatReturnsStringArray(0);
 
print myStr[0] " " myStr[1] "\n"

 


My suggestion is to avoid the

 

string function(parameters)[] { ... }

syntax. I had a bad error once using this syntax which was very hard to track down ... It seems to work very nice, but somehow it messes up the stack once in a while - unfortunately I cannot give an example. Just an advice - If you ever run into weird problems in any program part that make no sense, and you are using a function with that syntax change it back to void func(string &par[]) which does the trick but seems to be more stable.

Regards, Mathias
 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

If you ever find that example where

string PtrOps_castAsStringArray(int address)[] {
    string temp[];
    temp = (addr_ address);
    return (temp);
}
 
 
string functionThatReturnsStringArray()[] {
    // ...
    int address = someValidAddress();
    return( PtrOps_castAsStringArray(address) );
}


does not work, let me know. I've had my share of bad experiences with functions returning arrays too. When the smoke cleared, I've always found the real problem was the storage for that which I was returning got trashed (not the syntax itself).

See post
Link:Returning an array

comment at end and tell me what you think.